package com.lzc.springPart.aop.advisor;

import com.lzc.springPart.aop.PrintBefore;
import com.lzc.springPart.aop.ServiceImpl;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

public class PointcutDemo {

    public static void main(String[] args) throws NoSuchMethodException {

        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        // aspect表达式
        pointcut.setExpression("execution(* service())");
        // 判断是否匹配
        System.out.println(pointcut.matches(
                ServiceImpl.class.getMethod("service"), ServiceImpl.class
        ));

        AspectJExpressionPointcut annotation = new AspectJExpressionPointcut();
        // annotation表达式
        annotation.setExpression("@annotation(com.lzc.springPart.aop.PrintBefore)");
        // 判断是否匹配
        System.out.println(annotation.matches(
                ServiceImpl.class.getMethod("service"), ServiceImpl.class
        ));
    }
}
